<?php

/**
 * Created by JetBrains PhpStorm.
 * User: WEI JIAN XIANG
 * Date: 5/21/13
 * Time: 9:39 PM
 * To change this template use File | Settings | File Templates.
 */
class Core_Model_DbTable_DunnageInfoMaterial extends Zend_Db_Table_Abstract {

    protected $_name = "dunnage_info_material";

    public function getDunnageMaterial($dunnage_id = -1){
        if($dunnage_id == -1){
            return null;
        }
        $cond = $this->getAdapter()->quoteInto("dunnage_operation_id = (?)", $dunnage_id);
        $result = $this->fetchAll($cond)->toArray();
        $data = array();
        foreach($result as $item){
            $data[$item['dunnage_material_id']] = $item;
        }
        return $data;
    }

    public function getFullJoin($id = -1){
        if($id == -1){
            return null;
        }

        return $this->getAdapter()->fetchAll("
            select i.*, m.type, m.unit, m.price_per_unit
            from $this->_name i
            left join dunnage_materials m on m.id = i.dunnage_material_id
            where i.dunnage_operation_id = {$id}
        ");
    }
}